import 'package:xvideos/hj_page/mine_business/mine_vip/vip_support_model.dart';

import 'dc_model.dart';

class RechargeTypeModel {
  String? id;
  int? amount;
  int? money;
  String? typeName;
  String? subTitle;
  String? couponDesc;
  DCModel? daichong; // 从上级数据结构手动赋值过来
  int? giveGold;
  int? totalGold; //实际金币 = 金币+赠送金币
  int? firstGiveGold;

  List<RchgType>? rechargeTypeList;
  List<RchgType> get rechargeTypeListUI {
    List<RchgType> payList = [];
    List<String> payNameArr = ["支付寶(人工充值)", "微信(人工充值)", "银联(人工充值)", "信用卡(人工充值)", "花呗(人工充值)", "云闪付(人工充值)", "QQ錢包(人工充值)", "京东支付(人工充值)"];
    for (RchgType rechargeTypeBean in (rechargeTypeList ?? [])) {
      if (rechargeTypeBean.type == 'daichong') {
        if (daichong?.traders?.isNotEmpty == true) {
          PayForModel dcPayModel = daichong!.traders![0];
          if (dcPayModel.payInfos?.isNotEmpty == true) {
            for (PayInfoModel payInfoModel in dcPayModel.payInfos!) {
              var payType = RchgType();
              payType.isOfficial = true;
              payType.channel = rechargeTypeBean.channel;
              payType.incrAmount = rechargeTypeBean.incrAmount;
              payType.incTax = rechargeTypeBean.incTax;
              payType.payMethod = payInfoModel.payMethod;
              if (payInfoModel.payMethod == 101) {
                payType.type = 'alipy';
                payType.typeName = payNameArr[0];
              } else if (payInfoModel.payMethod == 102) {
                payType.type = 'wechat';
                payType.typeName = payNameArr[1];
              } else if (payInfoModel.payMethod == 103) {
                payType.type = 'union';
                payType.typeName = payNameArr[2];
              } else if (payInfoModel.payMethod == 104) {
                payType.type = 'credit';
                payType.typeName = payNameArr[3];
              } else if (payInfoModel.payMethod == 105) {
                payType.type = 'huabei';
                payType.typeName = payNameArr[4];
              } else if (payInfoModel.payMethod == 106) {
                payType.type = 'yunSanPay';
                payType.typeName = payNameArr[5];
              } else if (payInfoModel.payMethod == 107) {
                payType.type = 'qqWallet';
                payType.typeName = payNameArr[6];
              } else if (payInfoModel.payMethod == 108) {
                payType.type = 'jindongPay';
                payType.typeName = payNameArr[7];
              }
              payList.add(payType);
            }
          }
        }
      } else {
        payList.add(rechargeTypeBean);
      }
    }

    // RchgType couponType = RchgType();
    // couponType.type = "coupon";
    // couponType.typeName = "优惠券";
    // payList.insert(0, couponType);
    return payList;
  }

  //money是分单位  需要/100
  int get moneyYuan {
    return ((money ?? 0) / 100).round();
  }

  static RechargeTypeModel fromJson(Map<String, dynamic>? map) {
    map ??= {};
    RechargeTypeModel bean = RechargeTypeModel();
    bean.id = map['id'];
    bean.amount = map['amount'];
    bean.money = map['money'];
    bean.typeName = map['typeName'];
    bean.subTitle = map['subTitle'];
    bean.couponDesc = map['couponDesc'];
    bean.giveGold = map['giveGold'];
    bean.totalGold = map['totalGold'];
    bean.firstGiveGold = map['firstGiveGold'];
    bean.rechargeTypeList = (map['rchgType'] as List?)?.map((o) => RchgType.fromJson(o)).toList();
    return bean;
  }

  Map toJson() => {
        "id": id,
        "amount": amount,
        "money": money,
        "typeName": typeName,
        "subTitle": subTitle,
        "rchgType": rechargeTypeList,
        "couponDesc": couponDesc,
      };

  static List<RechargeTypeModel> toList(List<dynamic> mapList) {
    List<RechargeTypeModel> list = [];
    Iterator iterator = mapList.iterator;
    while (iterator.moveNext()) {
      Map<String, dynamic> current = iterator.current;
      list.add(fromJson(current));
    }
    return list;
  }
}

class RechargeTypeBean {
  String? type;
  String? typeName;
  String? channel;
  String? incrAmount; //增加的优惠额度
  String? incTax; //按比率增加额外优惠额 0-1之间 ,如果 incrAmount 与 incrTax 同时存在 以 incrAmount 为准

  //daichong 业务字段
  bool isOfficial = false;
  int? payMethod;

  static RechargeTypeBean fromMap(Map<String, dynamic>? map) {
    map ??= {};

    RechargeTypeBean rechargeTypeBean = RechargeTypeBean();
    rechargeTypeBean.type = map['type'];
    rechargeTypeBean.typeName = map['typeName'];
    rechargeTypeBean.channel = map['channel'];
    rechargeTypeBean.incrAmount = map.containsKey('incrAmount') ? map['incrAmount'].toString() : '0';
    rechargeTypeBean.incTax = map.containsKey('incTax') ? map['incTax'].toString() : '0';
    return rechargeTypeBean;
  }

  Map toJson() => {
        "type": type,
        "typeName": typeName,
        "channel": channel,
        "incrAmount": incrAmount,
        "incTax": incTax,
      };

  // String getIcon() {
  //   if (type == 'alipay') {
  //       return Assets.SVG_PAY_ICON101;
  //   } else if (type == 'wechat') {
  //     return AssetsSvg.SVG_PAY_ICON102;
  //   } else if (type == 'union') {
  //     return AssetsSvg.SVG_PAY_ICON103;
  //   } else {
  //     return AssetsSvg.SVG_PAY_ICON104;
  //   }
  // }

  String getIcon() {
    if (type == 'alipay') {
      return "assets/images/pay_icon/pay_icon101.png";
    } else if (type == 'wechat') {
      return "assets/images/pay_icon/pay_icon102.png"; //AssetsSvg.SVG_PAY_ICON102;
    } else if (type == 'coin') {
      //金币
      return "assets/images/pay_icon/pay_icon104.png";
    } else if (type == 'usdt') {
      return "assets/images/pay_icon/pay_icon105.png";
    } else {
      return "assets/images/pay_icon/pay_icon103.png";
    }
  }
}

class NewPrivilegeBean {
  String? img;
  String? privilegeName;
  String? privilegeDesc;

  bool? isHave;

  static NewPrivilegeBean fromMap(Map<String, dynamic>? map) {
    map ??= {};

    NewPrivilegeBean rechargeTypeBean = NewPrivilegeBean();
    rechargeTypeBean.img = map['img'];
    rechargeTypeBean.privilegeName = map['privilegeName'];
    rechargeTypeBean.privilegeDesc = map['privilegeDesc'];
    return rechargeTypeBean;
  }

  Map toJson() => {
        "img": img,
        "privilegeDesc": privilegeDesc,
        "isHave": isHave,
      };
}
